// eslint-disable-next-line
import { BasicLayout, BlankLayout, RouteView, UserLayout } from '@/layouts'

function parseId (str) {
  const id = parseInt(str)
  return isNaN(id) ? null : id
}

/**
 * 动态的菜单（路由）配置
 */
export const dynamicRouteConfigs = [

  {
    path: '/',
    name: 'index',
    component: BasicLayout,
    meta: { title: '首页' },
    redirect: '/dashboard/index',
    children: [

      // dashboard
      {
        path: '/dashboard',
        name: 'dashboard',
        redirect: '/dashboard/index',
        component: RouteView,
        hidden: true,
        hideChildrenInMenu: true,
        meta: { title: '统计', keepAlive: true, icon: 'folder', permission: 'Dashboard' }, // 星号表示：只要下级节点有权限，就显示本节点
        children: [
          {
            path: '/dashboard/index',
            name: 'DashboardIndex',
            component: () => import('@/views/dashboard/index'),
            meta: { title: '统计面板', keepAlive: false, icon: 'file', permission: 'Dashboard' },
          },
        ]
      },

      // System
      {
        path: '/system',
        name: 'system',
        redirect: '/system/permission-manage',
        component: RouteView,
        meta: { title: '系统管理', keepAlive: true, icon: 'folder', permission: '*' }, // 星号表示：只要下级节点有权限，就显示本节点
        children: [
          {
            path: '/system/user-manage',
            name: 'UserManage',
            component: () => import('@/views/system/UserManage/index'),
            meta: { title: '用户管理', keepAlive: false, icon: 'file', permission: 'UserManage' },
            hideChildrenInMenu: true,
            redirect: '/system/user-manage/list',
            children: [
              {
                path: '/system/user-manage/list',
                name: 'UserList',
                component: () => import('@/views/system/UserManage/UserList'),
                meta: { title: '用户列表', keepAlive: false, permission: 'UserManage.Query' }
              },
              {
                path: '/system/user-manage/create',
                name: 'UserCreate',
                component: () => import('@/views/system/UserManage/UserCreate'),
                meta: { title: '新增用户', keepAlive: false, permission: 'UserManage.Create' }
              },
              {
                path: '/system/user-manage/setting',
                name: 'UserSetting',
                component: () => import('@/views/system/UserManage/UserSetting'),
                meta: { title: '用户设置', keepAlive: false, permission: 'UserManage.Setting' }
              },
            ]
          },
          {
            path: '/system/role-manage',
            name: 'RoleManage',
            component: () => import('@/views/system/RoleManage/index'),
            meta: { title: '角色管理', keepAlive: false, icon: 'file', permission: 'RoleManage' },
            hideChildrenInMenu: true,
            redirect: '/system/role-manage/list',
            children: [
              {
                path: '/system/role-manage/list',
                name: 'RoleList',
                component: () => import('@/views/system/RoleManage/RoleList'),
                meta: { title: '角色列表', keepAlive: false, permission: 'RoleManage.Query' }
              },
              {
                path: '/system/role-manage/create',
                name: 'RoleCreate',
                component: () => import('@/views/system/RoleManage/RoleCreate'),
                meta: { title: '新增用户', keepAlive: false, permission: 'RoleManage.Create' }
              },
              {
                path: '/system/role-manage/edit',
                name: 'RoleEdit',
                component: () => import('@/views/system/RoleManage/RoleEdit'),
                meta: { title: '编辑角色', keepAlive: false, permission: 'RoleManage.Edit' }
              },
            ]
          },
          {
            path: '/system/permission-manage',
            name: 'PermissionManage',
            component: () => import('@/views/system/PermissionManage/index'),
            meta: { title: '权限管理', keepAlive: false, icon: 'file', permission: 'PermissionManage' },
            hideChildrenInMenu: true,
            redirect: '/system/permission-manage/index',
            children: [
              {
                path: '/system/permission-manage/index',
                name: 'PermissionIndex',
                component: () => import('@/views/system/PermissionManage/PermissionIndex'),
                meta: { title: '权限管理', keepAlive: false, icon: 'file', permission: 'PermissionManage' }
              }
            ]
          },
          {
            path: '/system/config-manage',
            name: 'ConfigManage',
            component: () => import('@/views/system/ConfigManage/index'),
            meta: { title: '配置管理', keepAlive: false, icon: 'file', permission: 'ConfigManage' }
          },
        ]
      },

      // biz
      {
        path: '/biz',
        name: 'biz',
        redirect: '/biz/product-manage',
        component: RouteView,
        meta: { title: '业务管理', keepAlive: true, icon: 'folder', permission: '*' },
        children: [
          {
            path: '/biz/dept-manage',
            name: 'DeptManage',
            component: () => import('@/views/biz/DeptManage/index'),
            meta: { title: '机构管理', keepAlive: false, icon: 'file', permission: 'DeptManage' }
          }
        ]
      },

      // account
      {
        path: '/account',
        component: RouteView,
        redirect: '/account/center',
        name: 'account',
        hidden: true,
        meta: { title: '个人页', icon: 'user', keepAlive: true },
        children: [
          {
            path: '/account/center',
            name: 'Center',
            component: () => import('@/views/account/center/Index'),
            meta: { title: '个人中心', keepAlive: true, permission: 'Center' }
          },
          {
            path: '/account/settings',
            name: 'Settings',
            component: () => import('@/views/account/settings/Index'),
            meta: { title: '个人设置', hideHeader: true, permission: 'Settings' },
            redirect: '/account/settings/security',
            hideChildrenInMenu: true,
            children: [
              {
                path: '/account/settings/security',
                name: 'SecuritySettings',
                component: () => import('@/views/account/settings/Security'),
                meta: { title: '安全设置', hidden: true, keepAlive: true, permission: 'Settings' }
              }
            ]
          }
        ]
      }

    ]
  },

  {
    path: '*', redirect: '/404', hidden: true
  }

]

/**
 * 静态的菜单（路由）配置
 */
export const staticRouteConfigs = [
  // login
  {
    path: '/user',
    component: UserLayout,
    redirect: '/user/login',
    hidden: true,
    children: [
      {
        path: 'login',
        name: 'login',
        component: () => import('@/views/user/Login'),
      }
    ]
  },
  // welcome (hidden)
  {
    path: '/welcome',
    name: 'welcome',
    component: BasicLayout,
    redirect: '/welcome/home',
    hidden: true,
    children: [
      {
        path: 'home',
        name: 'WelcomeHome',
        component: () => import('@/views/welcome'),
      }
    ]
  },

  {
    path: '/404',
    component: () => import('@/views/exception/404'),
  },

  {
    path: '/403',
    component: () => import('@/views/exception/403'),
  },

  {
    path: '/500',
    component: () => import('@/views/exception/500'),
  }

]
